#include "../Base/stdafx.h"
#include "./PhysX.h"
#include "ForceField.h"

ForceField::ForceField( const tstring& name, const D3DXVECTOR3& pos, const D3DXVECTOR3& force, const D3DXVECTOR3& size )
{
	m_Type = NXFORCEFIELD;
	m_Name = name;

	SetPosition(pos);

	NxForceFieldLinearKernelDesc linearKernelDesc;
	linearKernelDesc.constant = NxVec3(force.x, force.y, force.z);
	linearKernelDesc.velocityTarget = NxVec3(force.x, force.y, force.z);

	m_ForceKernel = PhysX::GetSingleton()->GetScene()->createForceFieldLinearKernel(linearKernelDesc);

	PhysXObject::Tick(0);
	NxMat34 mat;
	mat.setColumnMajor44(m_World);

	NxVec3 bSize = NxVec3(size.x/2, size.y/2, size.z/2);

	NxBoxShapeDesc bDesc;
	bDesc.dimensions = bSize;
	bDesc.mass = size.x * size.y * size.z;
	bDesc.shapeFlags |= NX_SF_DISABLE_COLLISION;

	NxActorDesc actorDesc;
	actorDesc.globalPose = mat;
	actorDesc.density = 10.0f;
	actorDesc.shapes.push_back(&bDesc);
	m_Actor = PhysX::GetSingleton()->GetScene()->createActor(actorDesc);

	NxForceFieldDesc fieldDesc;
	fieldDesc.kernel = m_ForceKernel;
	fieldDesc.actor = m_Actor;

	m_ForceField = PhysX::GetSingleton()->GetScene()->createForceField(fieldDesc);

	NxBoxForceFieldShapeDesc boxDesc;
	boxDesc.dimensions = bSize;

	m_ForceShape = m_ForceField->getIncludeShapeGroup().createShape(boxDesc);    

}

ForceField::~ForceField()
{
}

void ForceField::Tick( float dTime )
{
	PhysXObject::Tick(dTime);
	//NxMat34 mat = m_Actor->getGlobalPose();
	//mat->getColumnMajor44(m_World);
}